package com.formula.datastructure.exercise.tree;

public class HuffmanLinkNode {
    public Integer data;
    public HuffmanLinkNode left;
    public HuffmanLinkNode right;
    public HuffmanLinkNode parent;

    public String huffmanCode;

    public HuffmanLinkNode(Integer data) {
        this.data = data;
    }

    public void genHuffmanCode() {
        if (parent == null) {
            huffmanCode = "";
        }
        if (left != null) {
            left.huffmanCode = '0' + huffmanCode;
            left.genHuffmanCode();
        }
        if (right != null) {
            right.huffmanCode = '1' + huffmanCode;
            right.genHuffmanCode();
        }
    }
}
